<template>
	<view class="search">
		<view class="search_box">
			<u-search placeholder="请输入课程名称" v-model="keyword" :clearabled="true" @custom="handleSearch"
				@search="handleSearch" @clear="handleclearSearch"></u-search>
		</view>

		<view v-if="CourseList.length>0" class="">

			<view class="CourseList">
				<view class="Course_item" v-for="(item,index) in CourseList" :key="index"
					@click="handleCourseDetail(item,index)">
					<view class="Course_item_left">
						<image :src="item.defaultCoverAddress" mode="aspectFill"></image>
						<image v-if="item.chapterType == 1" class="videozz"
							src="https://mp.blrwworkshop.com/imgs/videoimg.png" mode="">
						</image>
					</view>
					<view class="Course_item_Content">
						<view class="name dot">
							{{item.chapterName}}
						</view>
						<view class="desc dot">
							<u-parse :content="item.chapterIntro"></u-parse>
						</view>
						<view class="progressBox">
							<view class="progres">
								<u-line-progress :percentage="item.progress || 0"
									:activeColor="role == 1 ? '#FFA116' : '#41C76F'"
									:showText="false"></u-line-progress>
							</view>
							<view class="" :class="role == 1 ? 'color_student' : 'color_parent'">
								{{item.progress ||0 }}%
							</view>
						</view>
					</view>
					<view v-if="item.isLatestWatched ==1" class="lastimg">
						<image
							:src=" role ==1 ? 'https://mp.blrwworkshop.com/imgs/lastimg.png' :'https://mp.blrwworkshop.com/imgs/lastimgs.png'"
							mode="">
						</image>
					</view>
				</view>
			</view>

		</view>

		<view v-else class="dataNull">
			<image
				:src="role==1?'https://mp.blrwworkshop.com/imgs/dataNull.png':'https://mp.blrwworkshop.com/imgs/dataNulls.png'"
				mode=""></image>
			<view class="">
				暂无课程列表
			</view>
		</view>

	</view>
</template>

<script>
	import {
		searchChapterList
	} from "@/api/course.js"
	export default {
		data() {
			return {
				role: uni.getStorageSync('role'),
				keyword: "",
				CourseList: [],
				pageNum: 1,
			}
		},
		methods: {
			async handleSearch() {
				if (this.keyword == "") {
					this.CourseList = []
					return
				}
				this.CourseList = []
				let res = await searchChapterList({
					chapterName: this.keyword,
					pageNum: this.pageNum,
					pageSize: 10,
				})
				if (res.code == 200) {
					this.CourseList = [...this.CourseList, ...res.rows]
				}
			},

			handleclearSearch() {
				this.CourseList = []
			},

			handleCourseDetail(item, index) {
				uni.navigateTo({
					url: `/pages/coursePackage/courseDetail/courseDetail?chapterId=${item.chapterId}`
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.search {
		width: 100%;
		min-height: 100vh;
		background: #F9F9F9;

		.search_box {
			width: 100%;
			padding: 20rpx;
			box-sizing: border-box;
			background-color: #ffffff;
		}

		.CourseList {
			width: 100%;
			margin-top: 20rpx;
			padding: 0 30rpx;
			box-sizing: border-box;

			.Course_item {
				width: 100%;
				height: 232rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				margin-bottom: 16rpx;
				display: flex;
				align-items: center;
				position: relative;

				.lastimg {
					position: absolute;
					top: 0;
					right: 0;
					width: 158rpx;
					height: 44rpx;
					z-index: 2;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.Course_item_left {
					// background-color: #FFEED4;
					border-radius: 20rpx;
					position: relative;

					.videozz {
						position: absolute;
						top: 0;
						left: 0;
					}

					image {
						width: 264rpx;
						height: 232rpx;
						border-radius: 20rpx;
					}
				}

				.Course_item_Content {
					width: 352rpx;
					margin-left: 26rpx;



					.name {
						font-weight: 600;
						font-size: 32rpx;
						color: #333333;
					}

					.desc {
						font-weight: 400;
						font-size: 24rpx;
						color: #B4B4B4;
						line-height: 34rpx;
						margin-top: 16rpx;
						max-height: 60rpx;
						overflow: hidden;
					}

					.dot {
						width: 100%;
						/* 必须设置固定宽度 */
						white-space: nowrap;
						/* 强制不换行 */
						overflow: hidden;
						/* 隐藏溢出内容 */
						text-overflow: ellipsis;
						/* 超出部分显示省略号 */
					}

					.progressBox {
						width: 100%;
						margin-top: 46rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;
						font-size: 24rpx;
						color: #FFA116;

						.progres {
							width: 80%;
						}
					}

				}
			}
		}

		.dataNull {
			width: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			margin-top: 200rpx;
			font-weight: 400;
			font-size: 32rpx;
			color: #DDDDDD;
			margin-top: 20rpx;

			image {
				width: 330rpx;
				height: 330rpx;

			}
		}
	}
</style>